#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <iostream>
#include <armadillo>
#include <iomanip>



/*
 * Dec 10-2013
 This will become a new project, as it's not aRiemmann clustering
 
 */
using namespace std;
using namespace arma;


#include "clustering_def.hpp"//Useful only for this .cpp
#include "clustering_impl.hpp" //Useful only for this .cpp




uword ro = 48;
uword co = 84;

//UQ
const std::string path = "/home/Johanna/codes-svn/dataset_ucsd_svn/"; 

//Home
//const std::string path = "/home/johanna/codes-svn/dataset_ucsd_svn/";

//NICTA
//const std::string path = "/home/johanna/codes-svn/my_UCSD/";

const std::string folder_means = "./Means_segm/";
//const std::string folder_r_pts = "./riemann_points/tmp_"; // Folder where Riemmannian Points are saved and loaded.
//const std::string folder_ker =  "./Kernel_matrix/Ker_tmp_"; // Folder where Riemmannian Points are saved and loaded.
const std::string  vNames = "video_names.txt";


void tmp_features();//Temporal features
void cal_Kernel_matrix_tmp();



int
main(int argc, char** argv)
{
  
  //To calculate Features and save in HD:
  //tmp_features();
  //To calculate Kernels using the points obtained with previous method.
  //cal_Kernel_matrix();
  
  
  //vi_names.print("vi_names");
  int summ_percentage = 10;
  
  field<std::string> frames_list;
  field<std::string> vi_names;
  vi_names.load(vNames);
  
  
    for (uword i = 0 ; i < 1; ++i)// vi_names.n_rows
    {
     
     std::stringstream toload_means;
     toload_means << folder_means << vi_names(i,0) <<".dat";
     cout << "Means to be loaded from " << toload_means.str() << endl;
     
     std::stringstream result;
     result <<"./Results/Perce="<< summ_percentage << "_" << vi_names(i,0) << ".dat";     
     
     std::stringstream GT;
     GT <<"./GT/new_Gp_annotations_" << vi_names(i,0) << ".dat";     // Ground Truth per Grassmann Point
     cout << "GT= " << GT.str() << endl;
     
     std::stringstream video_path;
     video_path << path << vi_names(i,0);
     
     std::stringstream frames_name;
     frames_name << video_path.str() << "/list.txt";
     cout << "frames_name "<< frames_name.str() << endl;
     frames_list.load(frames_name.str()); // se debe cargar por carpeta, tienen diferente # de frames.
     
     clustering_means cluster_means( toload_means.str(), result.str(), GT.str(), summ_percentage, video_path.str(), frames_list );
}
  
  
  return 0;
}


///Only using mean.
// Calculate features as per A. Sanin's paper 
//"Spatio-Temporal Covariance Descriptors for Action and Gesture Recognition". WACV_2013
//Eqs. 13, 14 and 15
void
tmp_features() 
{
  
  field<std::string> frames_list;
  field<std::string> vi_names;
  vi_names.load(vNames);
 
  
  
  for (uword i = 0 ; i < vi_names.n_rows; ++i)// vi_names.n_rows
  {
    cout << "i= " << i << endl;
    
    std::stringstream one_video;
    one_video << path <<  vi_names(i,0) <<"/";
    
    std::string video = one_video.str();
    
    
    std::stringstream frames_name;
    frames_name << video << "list.txt";
    cout << "frames_name "<< frames_name.str() ;
    frames_list.load(frames_name.str()); // se debe cargar por carpeta, tienen diferente # de frames.
    
    std::stringstream tosave_means;
    tosave_means << folder_means << vi_names(i,0) <<".dat";
    
    cout << "Means will be save at "<< tosave_means.str() << endl;
    
    
    clustering_means create_means( video, frames_list, ro, co, tosave_means.str());
  }
  
}


/*
 * cmake_minimum_required(VERSION 2.8)
 project( grassmann_clustering)
 find_package( OpenCV REQUIRED)
 find_package( Armadillo REQUIRED)
 add_executable( tmp_feats.exe temporal_features.cpp )
 target_link_libraries( tmp_feats.exe ${OpenCV_LIBS} -O1 -larmadillo)
 */